/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mock.servicesdirectory.web.action;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import java.util.logging.Level;
import java.util.logging.Logger;

import mock.servicesdirectory.dao.daointerface.GeographyDAO;
import mock.servicesdirectory.web.model.Geography;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class GeographyEditAction  extends ActionSupport
{
   private String oper;
   private String name;
   private String id;
   private static final Log    log              = LogFactory.getLog(GeographyEditAction.class);

    public String execute() throws Exception
    {
        Logger.getLogger("MyactionEdit ").log(Level.INFO, "Editing Action .java Called...");

        Geography cust;
        if(oper.equalsIgnoreCase("add"))
        {
            Logger.getLogger("MyactionEdit ").log(Level.INFO, "ADD customer");
            cust=new Geography();
            cust.setName(name);
            cust.setId(GeographyDAO.nextId());
            GeographyDAO.save(cust);
        }
        else if (oper.equalsIgnoreCase("edit"))
        {
            Logger.getLogger("MyactionEdit ").log(Level.INFO, "Edit customer");
            Logger.getLogger("MyactionEdit ").log(Level.INFO, "Edit ID : "+id);
            Logger.getLogger("MyactionEdit ").log(Level.INFO, "Edit new name : "+name);

            cust = GeographyDAO.findById(Integer.parseInt(id));
            cust.setName(name);
            GeographyDAO.update(cust);
        }
        else if (oper.equalsIgnoreCase("del"))
        {
            Logger.getLogger("MyactionEdit ").log(Level.INFO, "Delete customer");
            cust = GeographyDAO.findById(Integer.parseInt(id));
            if(cust!=null)  {            GeographyDAO.delete(cust);      }
        }
        return NONE;
    }

    public String getOper() {
        return oper;
    }

    public void setOper(String oper) {
        this.oper = oper;
    }

   
    public String getName() {
        return name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }
}
